﻿namespace Bizspoke.BizTalk.Adapter
{
    using Microsoft.Win32;
    using System;
    using System.Security.Permissions;

    internal class HelpMan
    {
        private static IHelp help;

        private HelpMan()
        {
        }

        public static void DisplayTopic(string url)
        {
            if (help == null)
            {
                Type typeFromProgID = Type.GetTypeFromProgID("DExplore.AppObj.8.0");
                if (typeFromProgID == null)
                {
                    typeFromProgID = Type.GetTypeFromProgID("DExplore.AppObj");
                }
                help = (IHelp) Activator.CreateInstance(typeFromProgID);
            }
            help.SetCollection("ms-help://MS.VSCC.2003", "");
            help.DisplayTopicFromURL(url);
            help.SyncContents(url);
        }

        [RegistryPermission(SecurityAction.Demand, Read=@"HKEY_LOCAL_MACHINE\Software\BizTalk Server\3.0")]
        public static bool IsHelpInstalled()
        {
            bool flag = false;
            using (RegistryKey key = Registry.LocalMachine.OpenSubKey(@"Software\Microsoft\BizTalk Server\3.0"))
            {
                if (key == null)
                {
                    return flag;
                }
                string str = key.GetValue("HelpInstalled") as string;
                if (str != null)
                {
                    flag = Convert.ToBoolean(Convert.ToInt32(str));
                }
                key.Close();
            }
            return flag;
        }
    }
}

